package com.kobeliu.entity;

import java.util.Date;

/**
 * leetCode 278
 *
 *
 */

public class Demo_26_No278 {

    private static boolean[] bs = {false,false,false,false,false,false,false,false,true,true,true,true,true};

    public static void main(String[] args) {

//        System.out.println(new Date().toString());
        System.out.println(firstBadVersion(13));
    }

    public static int firstBadVersion(int n) {
        //换了个样子的二分
        int L = 0;
        int R = n;
        if(n==0) return 0;
        if(n==1) return 1;
        while(L<R){
            int mid = L + ((R-L)>>1);
            if(isBadVersion(mid)){
                R = mid;
            }
            if(!isBadVersion(mid)){
                L = mid+1;
            }
        }
        return L;
    }

    private static boolean isBadVersion(int mid) {

        return bs[mid-1];
    }
}
